import tkinter as tk
from tkinter import ttk, filedialog
import pandas as pd
from utils import process_excel


class Attendance(ttk.Frame):
    def __init__(self, parent, controller):
        super().__init__(parent)
        label = ttk.Label(self, text="页面2")
        label.pack(pady=10, padx=10)
        from views import MainPage

        button = ttk.Button(self, text="返回主页面",
                            command=lambda: controller.show_frame(MainPage))
        button.pack()

        load_button = ttk.Button(self, text="上传Excel文件", command=self.load_file)
        load_button.pack()

    def load_file(self):
        filepath = filedialog.askopenfilename(filetypes=[("Excel files", "*.xlsx *.xls")])
        if filepath:
            process_excel(filepath, self.deal_data)

    def deal_data(self, df):
        print(df)
        return df
